package com.tros.admin.validation;


import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Encoder;

public class EncryptValue {	
	
	Cipher cip;
	SecretKeySpec keyValue;
	AlgorithmParameterSpec valSpecAlg ;
    byte[] encryptValue;
    String pass;
    String masterPass = "yogaEswaran12345";
    String retenOutput;
    
	
	public EncryptValue(String passwrd){
		
		try{
			
			this.pass = passwrd;			
			this.keyValue = new SecretKeySpec(masterPass.getBytes(), "AES");
			this.valSpecAlg = new IvParameterSpec(masterPass.getBytes()); 
			this.cip = Cipher.getInstance("AES/CBC/PKCS5Padding");			 
			
		}catch(Exception e)
		{
			System.out.println("Prob while starting encrypt "+e.getMessage());
		}
	}

	
	 public String getEncryptValue() {
		 
		 try
		 {
			 cip.init(Cipher.ENCRYPT_MODE, keyValue, valSpecAlg);			 
			 byte[] afterEnc = cip.doFinal(pass.getBytes());
			 this.retenOutput =  new BASE64Encoder().encode(afterEnc);		 
			 
		 }catch(Exception e)
		 {
			 System.out.println("Prob while sgetting encrypt "+e.getMessage());
		 }
		 
		 return retenOutput;
	 }
	
}




































